/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package group2assignone.ucm.manager;

import group2assignone.dao.MyDAO;
import group2assignone.model.Airport;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.UITool;
import group2assignone.view.manager.AddAirportView;
import group2assignone.view.manager.ManagerView;

/**
 * Use Case: Confirm add new airport                         <br>
 * Pre-condition: Useris in the add airport view and clicks confirm        .<br>
 * Post-condition: Manager Main view is displayed                           <br>
 * 1. system exits the current view                                         <br>
 * 2. System etrieves the new airport data                                  <br>
 * 3. System writes the data to the database                                <br>
 * 4. System restors Manager Main VIew                                      <br>
 *      1 a) Airport loaction is empty                                      <br>
 *              - display error                                             <br>
 *      1 b) Airport tax is empty                                           <br>
 *              - display error                                             <br>
 * @author group2
 */
public class UCConfirmAddAirport implements UCController{
    private AddAirportView view;
    private Airport airport;

    public UCConfirmAddAirport(AddAirportView view) {
       this.view = view;
       airport = new Airport();
    }

    public void run() {
        //1 a) Airport loaction is empty                                      <br>
        //        - display error                                             <br>
        if(view.getAirportLocation().length() == 0){
            System.out.println("invalid airport location");
            UITool.displayError("Airport Location Cannot be Blank", view);
        }
        //1 b) Airport tax is empty                                           <br>
        //         - display error                                             <br>
        else if(view.getAirTax().length() == 0){
            System.out.println("invlid tax");
            UITool.displayError("Airport Tax Cannot be Blank", view);
        }
        else{
            //1. system exits the current view
            view.dispose();
            //2. System etrieves the new airport data
            airport.setAirportLoc(view.getAirportLocation());
            airport.setAirportTax(Double.parseDouble(view.getAirTax()));
            //3. System writes the data to the database
            MyDAO coms = UCStartup.getInstance().getDAO();
            coms.sQLAddAirport(airport);
            //4. System restors Manager Main VIew
            ManagerView mv = ManagerView.getInstance();
            mv.go();
        }
    }
}
